package com.api.regression.group.deletemember;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(locations = { "classpath:/group/group-context.xml" })
public class DeleteMemberNotOwner extends AbstractApiTest {

	@Value("#{groupmembers['user.notOwner'].appId}")
	private String userUrn;

	@Value("#{groupmembers['user.notOwner'].password}")
	private String userPassword;

	@Value("#{groupmembers['group.toDelete'].urn}")
	private String groupUrn;

	@Value("#{groupmembers['user.toDelete'].appId}")
	private String memberToDeleteUrn;

	@BeforeClass
	public void loginUser() throws ZyncroApiException {

		getApi().login(userUrn, userPassword);
	}

	@Test(expectedExceptions = { ZyncroApiException.class })
	public void testDeleteMember() throws ZyncroApiException {

		getApi().getService(IGroupApiService.class).deleteMember(groupUrn, memberToDeleteUrn);
	}

	@AfterClass
	public void restoreUser() throws ZyncroApiException {

		boolean isEditor = false;
		boolean isTaskManager = false;
		boolean isInviter = false;
		boolean isCommenter = false;
		boolean isOwner = false;

		getApi().getService(IGroupApiService.class).addMember(groupUrn, memberToDeleteUrn, isEditor, isTaskManager, isInviter, isCommenter,
				isOwner);
	}
}
